home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3.iso
/
chapte23
/
ex4.c
< prev
Wrap
C/C++ Source or Header
|
1995-03-22
|
2KB
|
60 lines
#include <genstub.c>
// Menu options.
#include <atomtest.h>
// Atom name - constant string.
#define THE_ATOM "A global atom."
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch (uMsg) // Process Windows messages.
{
case WM_COMMAND: // Process menu items.
switch ( LOWORD( wParam ) )
{
case IDM_ADDATOM: // Adds an atom.
GlobalAddAtom( THE_ATOM );
InvalidateRect( hWnd, NULL, TRUE );
UpdateWindow( hWnd );
break;
case IDM_DELETEATOM: // Delete an atom.
if ( !GlobalFindAtom( THE_ATOM ) )
MessageBox( hWnd, "Atom no longer exists.", "Error Message", MB_OK );
else
GlobalDeleteAtom( GlobalFindAtom(THE_ATOM) );
InvalidateRect( hWnd, NULL, TRUE );
UpdateWindow( hWnd );
break;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
}
break;
case WM_PAINT:
{ // Show the results of searching for an atom.
ATOM aAnAtom;
PAINTSTRUCT ps;
char szWorkArea[33], szBuffer[128];
BeginPaint( hWnd, &ps );
if (aAnAtom = GlobalFindAtom( THE_ATOM )) {
GlobalGetAtomName( aAnAtom, szWorkArea, 32 );
wsprintf( szBuffer, "Atom '%s' was found.", szWorkArea );
}
else
lstrcpy( szBuffer, "Atom must be added." );
TextOut( ps.hdc, 0, 0, szBuffer, lstrlen( szBuffer ) );
EndPaint( hWnd, &ps );
}
break ;
case WM_DESTROY:
PostQuitMessage( 0 );
break ;
default:
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
return( 0L ) ;
}
#include <about.c>